﻿using System;
using System.Collections.Generic;
using System.Text;
using OpenSocialPlugin.General;
using MediaPortal.Configuration;
using MediaPortal.GUI.Library;


namespace OpenSocialPlugin.Providers.Sites.Facebook
{
    public class SiteSettings:SiteSettingsBase
    {
        private string token;
        public string Token
        {
            get
            {
                return token;
            }
            set
            {
                token = value;
            }
        }

        private string secret;
        public string Secret
        {
            get
            {
                return secret;
            }
            set
            {
                secret = value;
            }
        }

        private string session;
        public string Session
        {
            get
            {
                return session;
            }
            set
            {
                session = value;
            }
        }

        private string uid;
        public string Uid
        {
            get
            {
                return uid;
            }
            set
            {
                uid = value;
            }
        }
        public void Load()
        {
            using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml")))
            {
                this.User = xmlreader.GetValueAsString("opensocial", "FacebookUser", "");
                this.Password = xmlreader.GetValueAsString("opensocial", "FacebookPass", "");
                this.Token = xmlreader.GetValueAsString("opensocial", "FacebookToken", "");
                this.Uid = xmlreader.GetValueAsString("opensocial", "FacebookUid", "");
                this.Secret = xmlreader.GetValueAsString("opensocial", "FacebookSecret", "");
                this.Session = xmlreader.GetValueAsString("opensocial", "FacebookSession", "");

                this.Enabled = xmlreader.GetValueAsBool("opensocial", "FacebookEnabled", true);
            }
        }

        public void Save()
        {
            using (MediaPortal.Profile.Settings xmlwriter = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml")))
            {
                xmlwriter.SetValue("opensocial", "FacebookUser", this.User);
                xmlwriter.SetValue("opensocial", "FacebookPass", this.Password);
                xmlwriter.SetValue("opensocial", "FacebookToken", this.Token);
                xmlwriter.SetValue("opensocial", "FacebookUid", this.uid);
                xmlwriter.SetValue("opensocial", "FacebookSecret", this.Secret);
                xmlwriter.SetValue("opensocial", "FacebookSession", this.Session);


                xmlwriter.SetValueAsBool("opensocial", "FacebookEnabled", this.Enabled);
            }
        }
    }
}
